package com.uex.dev.manage.admin.vo.problem;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.uex.dev.manage.admin.enums.ProblemStatusEnum;
import com.uex.dev.manage.admin.po.ProblemPO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @author lzs
 * @create 2024/03/01
 * @description
 */
@Schema(description = "问题列表响应参数")
@Data
public class ProblemInfoResp {
    @Schema(description = "问题Id")
    private Integer id;
    @Schema(description = "问题所属设备Id")
    private Integer problemDevid;
    @Schema(description = "问题所属项目Id")
    private Integer problemPrjid;
    @Schema(description = "问题标题")
    private String problemTitle;
    @Schema(description = "问题联系人及电话")
    private String problemContact;
    @Schema(description = "问题详情")
    private String problemDesc;
    @Schema(description = "问题状态")
    private ProblemStatusEnum problemStatus;
    @Schema(description = "问题状态描述")
    private String problemStatusDesc;
    @Schema(description = "问题记录时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime problemTime;
    @Schema(description = "问题更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime problemUpdtime;

    public static ProblemInfoResp fromPO(ProblemPO problemPo) {
        ProblemInfoResp problemPageResp = new ProblemInfoResp();
        BeanUtils.copyProperties(problemPo, problemPageResp);
        problemPageResp.setProblemStatusDesc(Objects.nonNull(problemPo.getProblemStatus()) ? problemPo.getProblemStatus().getDesc() :"-");
        return problemPageResp;
    }
}

